package com.tw.trips.ui;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;

import com.tw.trips.service.helpers.DatabasePopulator;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.LoginForm;
import com.vaadin.ui.LoginForm.LoginEvent;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;

@Service
@Configurable(preConstruction = true)
public class MyTripsLoginForm extends VerticalLayout {
	
	public MyTripsLoginForm() {
        LoginForm login = new LoginForm();
        login.addListener(new LoginForm.LoginListener() {
            public void onLogin(LoginEvent event) {
                /*getWindow().showNotification(
                        "New Login",
                        "Username: " + event.getLoginParameter("username")
                                + ", password: "
                                + event.getLoginParameter("password"));*/
            	
            	//TODO : do login validation
            	MainPage mainPage = (MainPage)event.getComponent().getParent().getParent();
            	mainPage.removeComponent(mainPage.getComponent(1));
            	
            	
            	/*HomePageLayout homePage = new HomePageLayout();
            	mainPage.addComponent(homePage, 1);*/
            	
            	HorizontalSplitPanel horiz = new HorizontalSplitPanel();
            	horiz.setSplitPosition(50); // percent
            	mainPage.addComponent(horiz, 1);
            	
            }
        });
        addComponent(login);
        setComponentAlignment(login, Alignment.MIDDLE_CENTER);

    }
}
